<?php
namespace app\interfaces\controller;

use app\interfaces\model\Area as AreaModel;
use think\Request;
use think\Exception;

class Area
{

    /*
     * 用户端 - 省
     */
    public function province_list()
    {

        $result = AreaModel::where(['area_deep' => '1'])->field('area_id,area_name')->select();

        return ['code' => 200, 'message' => '成功', 'data' => $result];


    }

    /*
     * 用户端 - 市
     * @param  string $area_id 唯一标示
     */
    public function city_list()
    {

        // 获取参数
        $area_id = Request::instance()->param('area_id');

        if (empty($area_id)) throw new Exception('not Empty');

        // 验证数据
        $result = AreaModel::where(['area_parent_id' => $area_id])->field('area_id,area_name')->select();

        return ['code' => 200, 'message' => '成功', 'data' => $result];

    }


    /*
     * 用户端 - 区
     * @param  string $area_id 唯一标示
     */
    public function area_list()
    {

        // 获取参数
        $area_id = Request::instance()->param('area_id');

        if (empty($area_id)) throw new Exception('not Empty');

        // 验证数据
        $result = AreaModel::where(['area_parent_id' => $area_id])->field('area_id,area_name')->select();

        return ['code' => 200, 'message' => '成功', 'data' => $result];

    }

}
